<?php

namespace App\Http\Middleware;

use App\Models\ApiResult;
use App\Services\Base\MsgService;
use Closure;
use Illuminate\Http\Request;

class ClientHeaderLang
{
    /**
     * Handle an incoming request.
     *
     * @param \Illuminate\Http\Request $request
     * @param \Closure $next
     * @return mixed
     */
    public function handle(Request $request, Closure $next)
    {
        // 获取请求头中的语言
        $lang = MsgService::getLang($request);
        // 匹配语言，进行语言设置
//         \App::setLocale($lang);
        app()->setLocale($lang);

        return $next($request);
    }
}
